import Arena from '@colyseus/arena'
import { RequestContext } from '@mikro-orm/core'
import express from 'express'
import { DI } from './config/database.config'
import userRoutes from './routes/userRoutes'
import { monitor } from '@colyseus/monitor'
import { GameRoom } from './rooms/GameRoom'

export default Arena({
  getId: () => 'hmc-buyu-room',
  initializeGameServer: (gameServer) => {
    gameServer.define('chat', GameRoom)
  },
  initializeExpress: (app) => {
    app.use(express.json())
    app.use(express.urlencoded({ extended: true, limit: '10kb' }))

    app.use((req, res, next) => RequestContext.create(DI.orm.em, next))

    app.use('/users', userRoutes)

    app.get('/', (req, res) => {
      res.send('Hello world')
    })

    app.use('/colyseus', monitor())
  },
})